#coding=utf-8
'''
Created on 2013-9-3

@author: Ben

世界
'''

from ..common import Command, Logger, RequestModel
from ..common.SocketService import gameSocketService
from ..war import WarData
import WorldData

'''
获取世界信息
'''
class WorldGetInfoRequest(RequestModel.RequestModel):

    def setCommand(self):
        self.command = Command.GET_WORLD_INFO
        
    def onReceive(self, data):
        Logger.log("获取世界信息成功", output = True)
        WorldData.init(data)

'''
武将移动
'''
def startGeneralMove(cityId, generalId):
    command = Command.START_MOVE
    params = 'cityId=' + str(cityId) + '&generalId=' + str(generalId)
    gameSocketService.send(command, params, startGeneralMoveCallback)

'''
城市更新
'''
def cityInfoUpdate(data):
    WorldData.update(data)
    
'''
武将移动回调函数
'''
def startGeneralMoveCallback(data):
    Logger.log('武将移动', output = True)

'''
获取城市信息
'''
def getCityInfo(cityId):
    command = Command.GET_CITY_INFO
    params = 'cityId=' + str(cityId)
    gameSocketService.send(command, params, getCityInfoCallback)

'''
获取城市信息回调函数
'''
def getCityInfoCallback(data):
    if 'inBattle' in data and data['inBattle']:
        if 'battleId' in data:
            WarData.battleId = data['battleId']
            
'''
领取整点杀敌奖励
'''
def getHourKillReward():
    command = Command.GET_HOUR_KILL_REWARD
    params = ''
    gameSocketService.send(command, params, getHourKillRewardCallback)
    
'''
领取整点杀敌奖励回调函数
'''
def getHourKillRewardCallback(data):
    if 'rewards' in data:
        if 'type' in data['rewards'][0] and 'value' in data['rewards'][0]:
            Logger.log('领取整点杀敌奖励, type:' + str(data['rewards'][0]['type'])\
                        + ', num:' + str(data['rewards'][0]['value']))